package com.example.zyfypt_611cgt.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.zyfypt_611cgt.R;
import com.example.zyfypt_611cgt.adapter.VideoAdapter;
import com.example.zyfypt_611cgt.bean.VideoBean;
import com.example.zyfypt_611cgt.iface.VideoListener;
import com.example.zyfypt_611cgt.model.VideoModel;


import java.util.List;

public class Fragment31 extends BaseFragment{
    private List<VideoBean> list;
    private RecyclerView recyclerView;
    private VideoAdapter adapter;

    private VideoListener listener = new VideoListener() {
        @Override
        public void onResponse(List<VideoBean> beanList) {
            list = beanList;
            adapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "失败：", Toast.LENGTH_SHORT).show();
        }
    };

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment31, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("--fragment31--" + getSessionID());
        initRecyclerView(view);
        VideoModel model = new VideoModel();
        model.getResultList("video", 1, getSessionID(), listener);
    }

    private void initRecyclerView(View view) {
        recyclerView = view.findViewById(R.id.recyclerview31);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        adapter = new VideoAdapter(context);
        recyclerView.setAdapter(adapter);
    }
}
